package com.ruyuan.payment.business.controller;

import com.ruyuan.payment.server.req.CourseAddReq;
import com.ruyuan.payment.server.req.CourseModifyReq;
import com.ruyuan.payment.server.req.CourseQueryReq;
import com.ruyuan.payment.server.resp.CommonResp;
import com.ruyuan.payment.server.resp.CourseQueryResp;
import com.ruyuan.payment.server.resp.PageResp;
import com.ruyuan.payment.server.service.CourseService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("/course")
public class CourseController {

    @Resource
    private CourseService courseService;

    @GetMapping("/query-list")
    public CommonResp queryList(@Valid CourseQueryReq req) {
        CommonResp<PageResp<CourseQueryResp>> commonResp = new CommonResp<>();
        PageResp<CourseQueryResp> list = courseService.queryList(req);
        commonResp.setContent(list);
        return commonResp;
    }

    @PostMapping("/add")
    public CommonResp add(@RequestBody @Valid CourseAddReq req) {
        courseService.add(req);
        return new CommonResp();
    }

    @PostMapping("/modify")
    public CommonResp modify(@RequestBody @Valid CourseModifyReq req) {
        courseService.modify(req);
        return new CommonResp();
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id) {
        courseService.delete(id);
        return new CommonResp();
    }

}
